package com.talent.web.controller;

import com.talent.web.annotation.TalentLog;
import com.talent.web.enums.ActionType;
import com.talent.web.model.TalentResult;
import com.talent.web.model.dto.SysMenuDto;
import com.talent.web.model.vo.SysMenuVo;
import com.talent.web.service.ISysMenuService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @ClassName：MenuController
 * @Author: hszhou
 * @Date: 2024/10/21 13:35
 * @Description: 菜单控制器
 */
@RestController
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private  ISysMenuService menuService;

    @PostMapping
    @TalentLog(action= ActionType.INSERT,module = "菜单")
    public TalentResult<Null> addMenu(@RequestBody SysMenuDto dto){
        menuService.save(dto);
        return TalentResult.success(null);
    }

    @DeleteMapping("{id}")
    @TalentLog(action= ActionType.DELETE,module = "菜单")
    public TalentResult<Null> deleteMenu(@PathVariable("id")Long id){
        menuService.deleteMenuById(id);
        return TalentResult.success(null);
    }

    @PutMapping
    @TalentLog(action= ActionType.UPDATE,module = "菜单")
    public TalentResult<Null> updateMenu(@RequestBody SysMenuDto dto){
        menuService.update(dto);
        return TalentResult.success(null);
    }

    @GetMapping("/{id}")
    @TalentLog(action= ActionType.SEARCH,module = "菜单")
    public TalentResult<SysMenuVo> detail(@PathVariable("id")Long id){
        return TalentResult.success(menuService.detail(id));
    }

    @GetMapping("/current")
    public TalentResult<List<SysMenuVo>> menu(){
        List<SysMenuVo> currentMenu = menuService.getCurrentMenu();
        return TalentResult.success(currentMenu);
    }


    @GetMapping("list")
    public TalentResult<List<SysMenuVo> > list(){
        List<SysMenuVo> list = menuService.lists();
        return TalentResult.success(list);
    }

    @GetMapping("option")
    public TalentResult< List<SysMenuVo> > option(){
        List<SysMenuVo> list = menuService.option();
        return TalentResult.success(list);
    }
}
